<?php
/**
* qikDropShipper Extension
*
* @category   FavoredMinds
* @package    Vendor
* @author     FavoredMinds Solution (geedubya15@gmail.com)
* @copyright  Copyright (c) 2010 FavoredMinds.com (http://www.favoredminds.com)
*/

class PLUTUS_Home_Block_Home extends Mage_Core_Block_Template
{
    public function _prepareLayout()
    {
        return parent::_prepareLayout();
    }
    
    public function getThumbnailImageUrl($category){
    
        $url = false;
        
        if ($image = $category->getThumbnail()) {
            $url = Mage::getBaseUrl('media').'catalog/category/'.$image;
        }
        

        return $url;
    }
    public function getDefaultCategory(){
        
        $store = Mage::app()->getStore();

        $category = Mage::getModel('catalog/category')->getCollection()

            ->setStore($store)
            ->addAttributeToSelect(array("name","id","url"))
            ->addAttributeToFilter('is_active',true)
            ->addFieldToFilter("entity_id", array("neq"=>array(ROOT_CATEGORY)))
            ->addFieldToFilter("entity_id", array("neq"=>array(HIDE_CATEGORY)))
            ->addAttributeToSort('level', 'ASC')
            ->addAttributeToSort('position', 'ASC')
            ->getFirstItem();
       if(!empty($category)){
           return $category;
       }
       return false;
    }
    /*
    public function getDefaultCategory(){

        $store = Mage::app()->getStore();

        $category = Mage::getModel('catalog/category')->getCollection()

            ->setStore($store)
            ->addAttributeToSelect("*")
            ->addAttributeToFilter('is_active',true)
            ->addFieldToFilter("entity_id", array("neq"=>array(ROOT_CATEGORY)))
            ->addFieldToFilter("entity_id", array("neq"=>array(HIDE_CATEGORY)))
            ->addAttributeToSort('level', 'ASC')
            ->addAttributeToSort('position', 'ASC')
            ->getFirstItem();
       if(!empty($category)){
           return $category;
       }
       return false;
    }
    */
    public function getCategoryListOnHome(){
        
        $store = Mage::app()->getStore();
        
        $collectionList = Mage::getModel('catalog/category')->getCollection()
                
            ->setStore($store)
            ->addAttributeToSelect("*")
            ->addAttributeToSelect("thumbnail")    
            ->addAttributeToFilter('is_active',true)
            ->addAttributeToFilter('level',DEFAULT_LEVEL)
            ->addAttributeToFilter('on_slide',true)
            ->addFieldToFilter("entity_id", array("neq"=>array(ROOT_CATEGORY)))
            ->addFieldToFilter("entity_id", array("neq"=>array(HIDE_CATEGORY)))
            ->addAttributeToSort('level', 'ASC')
            ->addAttributeToSort('position', 'ASC');

        if(count($collectionList) > 0){
            return $collectionList;
        }
        
        return false;
    }
    public function getAllManufacture($limit=0)
    {
        $product = Mage::getModel('catalog/product');
        $attributes = Mage::getResourceModel('eav/entity_attribute_collection')
                  ->setEntityTypeFilter($product->getResource()->getTypeId())
                  ->addFieldToFilter('attribute_code', 'manufacturer');
        $attribute = $attributes->getFirstItem()->setEntity($product->getResource());
        $manufacturers = $attribute->getSource()->getAllOptions(false);
        if($limit==0)
            return $manufacturers;
        else{
            $new_manu = array();
            $i = 0;
            foreach($manufacturers as $manu){
                $new_manu[$i]['value']  = $manu['value'];
                $new_manu[$i]['label']  = $manu['label'];
                $i++;
                if($i==NUMBER_BRAND_ON_HOMEPAGE){
                    break;
                }
            }
            
            return $new_manu;
        }


    }
    public function getCatalog($alpha){
        if(empty($alpha)){
            $alpha = strtolower($this->getRequest()->getParam("alpha"));
        }
        
        $categories = Mage::getModel("catalog/category")->getCategories(ROOT_CATEGORY,
                                                $recursionLevel = 1,
                                                $sorted=true,
                                                $asCollection=true,
                                                $toLoad=true);
        if(empty($alpha)){
            return $categories;
        }

        $categories_filter = array();
        if(count($categories) > 0){
            foreach($categories as $_cate){
                //$row = $categories[$i];
                $alpha2 = strtolower(substr($_cate->getName(),0,1));
                
                if($alpha == $alpha2){
                    $categories_filter[] = $_cate;
                }
            }
        }
        
        return $categories_filter;
    }
   
}
	
	
?>